# coding = utf-8

'''
将Liver index的索引转换成全部的索引
'''

import cv2,os
import numpy as np
import matplotlib.pyplot as plt
import SimpleITK as sitk
from PIL import Image
import math

def liver_index_2_all_index(case_id, origion_id, index):
    big_image = "E:\Dataset\Liver\qiye\DongBeiDaXue2\image_venous\\data2_{}_venous.mha".format(origion_id)
    big_liver = "E:\Dataset\Liver\qiye\DongBeiDaXue2\liver\\data2_{}_liver_label.mha".format(origion_id)

    big_liver = sitk.GetArrayFromImage(sitk.ReadImage(big_liver))

    for i in range(big_liver.shape[0]):
        if index == 0:
            return i
        if big_liver[i].sum() > 0 :
            index -= 1



if __name__ == '__main__':
    index = liver_index_2_all_index(case_id="77", origion_id="0762", index=134)
    print(index)